﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _04_多播委托_无参无返回值
{
    public delegate void MyDelegate();
    class Person
    {

        public string Name { get; set; }

        public Person(string name)
        {
            Name = name;
        }

        public void SayHello()
        {
            Console.WriteLine("大家好，我是: {0}", Name);
        }
    }

    internal class Program
    {
        static void Main(string[] args)
        {
            Person pr1 = new Person("嘉嘉老师");
            Person pr2 = new Person("罗老师");
            Person pr3 = new Person("蔡老师");

            MyDelegate myDelegate = new MyDelegate(pr1.SayHello);
            myDelegate += new MyDelegate(pr2.SayHello);
            myDelegate += new MyDelegate(pr3.SayHello);

            //调用所持有的所有方法
            myDelegate.Invoke();

            Console.Read();
        }
    }
}
